﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace Celsius.AnimeTools.AssAnalytic
{
	public class ScriptInfo
	{
		/// <summary>
		/// dll信息。
		/// </summary>
		private const string constant = "; //// This ass file is rebuild by AnimeAssAnalytic.dll/r/n; //// Build by Foasis // 绿叶之砚/r/n; //// foasis@qq.com/r/n; //// lvyezhiyan@hotmail.com/r/n";
		/// <summary>
		/// [Script Info]所有信息。
		/// </summary>
		private List<string> content;

		/// <summary>
		/// ASS文件头部信息。
		/// </summary>
		public ScriptInfo()
		{
			this.content = new List<string>();
		}
		/// <summary>
		/// 字幕分辨率X轴。
		/// </summary>
		public int PlayResX
		{
			get;
			set;
		}

		/// <summary>
		/// 字幕分辨率Y轴。
		/// </summary>
		public int PlayResY
		{
			get;
			set;
		}

		/// <summary>
		/// [Script Info]所有信息。
		/// </summary>
		public List<string> Content
		{
			get
			{
				return this.content;
			}
			set
			{
				this.content = value;
			}
		}

		/// <summary>
		/// 填充ScriptInfo类属性。
		/// </summary>
		/// <param name="str">行内容。</param>
		public virtual void Build(string str)
		{
			var rx = new Regex(@"PlayResX\s*:\s*(\d+)");
			var ry = new Regex(@"PlayResY\s*:\s*(\d+)");
			var mx = rx.Match(str);
			var my = ry.Match(str);
			if (mx.Success)
				this.PlayResX = int.Parse(mx.Groups[1].Value);
			else if (my.Success)
				this.PlayResY = int.Parse(my.Groups[1].Value);
			else if (string.IsNullOrWhiteSpace(str))
				this.Content.Add(str);
		}
	}
}
